package main

import "fmt"

func main() {
	p1 := Add2()
	fmt.Printf("Call Add2 for 3 gives: %v\n", p1(3))
	p2 := Addr(2)
	fmt.Printf("The result is: %v\n", p2(3))
	var p3 = Adder()
	fmt.Printf("Adder result is: %v\n", p3(3))
}

func Add2() func(b int) int {
	return func(b int) int {
		return b + 2
	}
}

func Addr(i int) func(b int) int {
	return func(b int) int {
		return i + b
	}
}

func Adder() func(int) int {
	var x int
	return func(b int) int {
		x += b
		return x
	}
}
